<?php
namespace App\Service\User;
use App\Model\UserProfile;
use App\Model\Setting\SettingAppHidden;

/**
 * 感兴趣列表
 * Class LikeTagService
 * @package App\Service\User
 */
class LikeTagService extends UserBaseService
{
    protected $pageNum = 20;
    public function handle()
    {
        $userId = $this->getUserId();
        $page = $this->request->input('page', 1);
        $profile = UserProfile::getProfile($userId);
        $ret['list'] = [];
        $gender = $profile->gender == 1 ? 0 : 1;
        //排除自己
        $start = ($page - 1) * $this->pageNum;
        $role = $gender == 1 ? UserProfile::ROLE_USER : UserProfile::ROLE_HOST;
        $appId = $this->request->input('appid', 1);
        $channel = $this->request->input('channel',0);
//        $version = $this->request->input('version','1.0.0');
//
//        if ($appId == 101 && $channel == 502){
//            $usersInfo = UserProfile::getTestUserId($role, $gender, $start,$this->pageNum,[],false);
//        }else{
            $usersInfo = UserProfile::getTagUserList($role, $gender, $start,$this->pageNum,[],false);
//        }
//        $usersInfo = UserProfile::getTagUserList($role, $gender, $start,$this->pageNum,[],false);

        $newTime = strtotime(date('Y-m-d'));
        $ret = ['list' => []];
        array_walk($usersInfo, function ($userProfile) use (&$ret,$newTime) {

            $userProfileInfo = get_object_vars($userProfile);
            $newFlag = strtotime($userProfileInfo['created_at']) >= $newTime ? 1 : 0;
            $item = UserProfile::buildUserItem($userProfileInfo,[],100,true);

            $list = [
                'user_id' => $item['user_id'],
                'avatar' => $item['avatar'],
                'im_account' => $item['im_account'],
                'nick_name' => $item['nick_name'],
                'real_avatar' => $item['real_avatar'],//1真人认证，0未认证
                'new_flag' => $newFlag,//1新人，不是
            ];
            $ret['list'][] = $list;
        });

        return $ret;
    }
}
